new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Data: "dealer_info",
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),//状态
        page: 1,			//页数
        limit: 10
      },
      formData: {},
      tableData: [{}],		//表格数据
      total: 1,
      dialogForm: false,
      title: '',
      multipleSelection: [],
      key: '',
    }
  },
  mounted() {
    this.getList1(this.form);
  },
  methods: {
    onSerach() {				//查询方法
      if (this.key !== "") {
        this.form.Primary_Key = this.key;
        this.form.Primary_Key_Name = 'Dealer_Name';
        this.form.page = 1;
        this.form.limit = 10;
      } else {
        delete this.form.Primary_Key;
        delete this.form.Primary_Key_Name;
      }
      this.getList1(this.form);
    },
    //上一页
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList1(this.form);
    },
    // 下一页
    handleSizeChange(val) {
      this.form.page = 1
      this.form.limit = val;
      this.getList1(this.form);
    },
    addContract() {
      console.log("跳转")
    },
    getList1(data) {
      let _this = this
      $.ajax({
        type: 'POST',
        url: DomainName + '/getTableInquiryAction?token=' + $.cookie("token"),
        data,
        success: function (data) {
          _this.tableData = data.tableData;
          _this.total = Number(
            data.limit
          );
          console.log(_this.tableData)
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    // getList() {     //换页方法
    //   let _this = this
    //   $.ajax({
    //     type: 'POST',
    //     //	url: "../getContractListByConditionAction",
    //     url: "../getListByTableNameAction",
    //     data: {
    //       Data: "enterprise_info",
    //       token: $.cookie("token")
    //     },
    //     complete: function (XMLHttpRequest) {
    //       _this.loading = false
    //       if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
    //         window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
    //       }
    //     },
    //     success: function (Result) {
    //       console.log(Result);
    //       _this.tableData = Result      //将获取的数据存到表格数据中
    //     },
    //     dataType: "json"
    //   });
    // },
    addEnterprise() {
      window.location.href = './Add.html'
    },
    showMember(Sales_Unit_Price_SerialNumber) {
      sessionStorage.setItem("Sales_Unit_Price_SerialNumber", Sales_Unit_Price_SerialNumber)
      window.location.href = './show.html?Sales_Unit_Price_SerialNumber=' + Sales_Unit_Price_SerialNumber
    },
    editMember(Dealer_SerialNumber) {
      sessionStorage.setItem("Dealer_SerialNumber", Dealer_SerialNumber
      )
      window.location.href = './Edit.html'
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    onExcel() {
      /* generate workbook object from table */
      //  .table要导出的是哪一个表格
      var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
      /* get binary string as output */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        //  name+'.xlsx'表示导出的excel表格名字
        saveAs(
          new Blob([wbout], {
            type: "application/octet-stream"
          }),
          "销售价格单" + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    deletMember(Dealer_SerialNumber) {
      console.log(Dealer_SerialNumber);
      this.$confirm('此操作将作废该销售价格单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.delete(Dealer_SerialNumber);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    delete(Dealer_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/getInquiryIDOriginal?token=' + $.cookie("token"), //查
        data: {
          Primary_Key_Name: 'Dealer_SerialNumber',
          Primary_Key: Dealer_SerialNumber,
          Data: 'dealer_info',
        },
        success: function (res) {
          if (res.length == 1) {
            res[0].Row_Status = '1'
            let data = { Data: JSON.stringify({ Modify: { dealer_info: [res[0]] } }) };
            $.ajax({
              url: DomainName + '/GoodsFileEdit',
              type: 'POST',
              data,
              success: function (re) {
                if (re.Status == "success") {
                  _this.$message.success("作废成功")
                  _this.getList1(_this.form);
                }
              },
              error: function () {
                _this.$message.error("删除失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              },
            })
          }
        }
      })
    }
  },
})